import { _decorator, Component, Node,screen } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('UIManager')
export class UIManager extends Component {
    public static instance:UIManager;
    private lastScreenDir: number = -1;//0 横屏 1 竖屏

    public onScreenDirChanged:(dir:number) => void = () => {}; // 整个路径完成的事件

    protected onLoad(): void {
        UIManager.instance = this;
    }

    update(deltaTime: number) {
        this.updateScreenDir();
    }

    updateScreenDir(){
        if(screen.windowSize.width > screen.windowSize.height){
            //变成横屏
            if(this.lastScreenDir != 0){
                this.lastScreenDir = 0;
                this.onScreenDirChanged(this.lastScreenDir);
            }
        }
        else{
            //变成竖屏
            if(this.lastScreenDir != 1){
                this.lastScreenDir = 1;
                this.onScreenDirChanged(this.lastScreenDir);
            }
        }
    }
}


